package com.zhuzi.demo;

import cn.hutool.core.io.FileUtil;
import com.google.common.collect.Lists;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class StreamDemo {
    @Test
    public void flatMap() {
        Person person = new Person().setCId(1L).setUId(2L);
        Person person2 = new Person().setCId(3L).setUId(4L);
        ArrayList<Person> people = Lists.newArrayList(person, person2);

        List<ArrayList<Long>> collect = people.stream().map(item -> Lists.newArrayList(item.getCId(), item.getUId())).collect(Collectors.toList());

        List<Long> collect1 = collect.stream().flatMap(item -> item.stream()).collect(Collectors.toList());
        System.out.println(collect);
        System.out.println(collect1);
    }

    @Data
    @Accessors(chain = true)
    public static class Person {
        private Long cId;
        private Long uId;
    }

    @Test
    public void test() {

        String readString = FileUtil.readString("/Users/zhuzi/workspace/a-wk/H-跨境电商/B-真实报文/订单申报报文.txt", StandardCharsets.UTF_8);
        String s = StringUtils.substringBetween(readString, "CEB", "Message");
        System.out.println(s);
    }
}
